﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using transportsystem.DTO;
using UTIL;

namespace transportsystem.DAO
{
    public class PhanQuyenDAO
    {
        public static DataTable getPhanQuyenList()
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuPhanQuyen '', '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , ''";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }

        public static bool updatePhanQuyen(PhanQuyen x)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_ThemPhanQuyen");
            cmd.Parameters.Add("@maphanquyen", SqlDbType.Int).Value = x.Maphanquyen;
            cmd.Parameters.Add("@capnhattaikhoan", SqlDbType.Int).Value = x.Capnhattaikhoan;
            cmd.Parameters.Add("@dangnhap", SqlDbType.Int).Value = x.Dangnhap;
            cmd.Parameters.Add("@dangxuat", SqlDbType.Int).Value = x.Dangxuat;
            cmd.Parameters.Add("@tracuu", SqlDbType.Int).Value = x.Tracuu;
            cmd.Parameters.Add("@thaotacdatve", SqlDbType.Int).Value = x.Thaotacdatve;
            cmd.Parameters.Add("@capnhatthongtinve", SqlDbType.Int).Value = x.Capnhatthongtinve;
            cmd.Parameters.Add("@thaotachuyve", SqlDbType.Int).Value = x.Thaotachuyve;
            cmd.Parameters.Add("@dieuphoichuyenxe", SqlDbType.Int).Value = x.Dieuphoichuyenxe;
            cmd.Parameters.Add("@quanlydaily", SqlDbType.Int).Value = x.Quanlydaily;
            cmd.Parameters.Add("@quanlydatve", SqlDbType.Int).Value = x.Quanlydatve;
            cmd.Parameters.Add("@quanlykhachhang", SqlDbType.Int).Value = x.Quanlykhachhang;
            cmd.Parameters.Add("@tinhchiphi", SqlDbType.Int).Value = x.Tinhchiphi;
            cmd.Parameters.Add("@thongkenhanvien", SqlDbType.Int).Value = x.Thongkenhanvien;
            cmd.Parameters.Add("@thongkedoanhthu", SqlDbType.Int).Value = x.Thongkedoanhthu;
            cmd.Parameters.Add("@baocaodoanhthu", SqlDbType.Int).Value = x.Baocaodoanhthu;
            cmd.Parameters.Add("@quanlyhoadon", SqlDbType.Int).Value = x.Quanlyhoadon;
            cmd.Parameters.Add("@quanlykhohang", SqlDbType.Int).Value = x.Quanlykhohang;
            cmd.Parameters.Add("@quanlylichtrinh", SqlDbType.Int).Value = x.Quanlylichtrinh;
            cmd.Parameters.Add("@quanlynguoidung", SqlDbType.Int).Value = x.Quanlynguoidung;
            cmd.Parameters.Add("@quanlynhanvien", SqlDbType.Int).Value = x.Quanlynhanvien;
            cmd.Parameters.Add("@quanlytuyenxe", SqlDbType.Int).Value = x.Quanlytuyenxe;
            cmd.Parameters.Add("@quanlyxe", SqlDbType.Int).Value = x.Quanlyxe;

            return SqlDataAccessHelper.ExecCmd(cmd);
        }

        public static bool deletePhanQuyen(PhanQuyen x)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_XoaPhanQuyen");
            cmd.Parameters.Add("@maphanquyen", SqlDbType.Int).Value = x.Maphanquyen;
            return SqlDataAccessHelper.ExecCmd(cmd);
        }

        //tcp update
        public static DataTable layPhanQuyenTheoMa(int mapq)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_LayPhanQuyenTheoMa";
            SqlParameter[] sp = new SqlParameter[1];
            sp[0] = new SqlParameter("@maphanquyen", mapq);            
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, sp);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
    }
}
